﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AccountServiceReference;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session["User"] == null)
        //{
        //    Response.Redirect("Product.aspx");
        //}
        MultiView1.ActiveViewIndex = Session["User"] == null ? 0 : 1;

    }
    protected void lbtnSignIn_Click(object sender, EventArgs e)
    {
        var client = new AccountServiceClient();
        var username = txtUsername.Text.Trim();
        var password = txtPassword.Text.Trim();
        var account = client.SignIn(username, password);
        if (account == null)
        {
            msg.Text = "Login Failed! Please try again!";
        }
        else
        {
            Session["User"] = username;
            Session["Role"] = account.IsAdmin;
            MultiView1.ActiveViewIndex = 1;
            Response.Redirect(account.IsAdmin ? "ProductManagement.aspx" : "Product.aspx");
        }
    }
    protected void btnLogout_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        Session.Abandon();
        Session.Clear();
        Response.Redirect("Product.aspx");
    }
}
